package com.gouwudai.gobbs.service.impl;

import javax.servlet.http.HttpServletRequest;

import com.gouwudai.gobbs.dao.ISysInfoDAO;
import com.gouwudai.gobbs.pojo.TbbsSysInfo;
import com.gouwudai.gobbs.service.ISysInfoService;
import com.gouwudai.gobbs.vo.SysInfoVO;
import com.litt.core.cache.OSCacheManager;
import com.litt.core.tools.beanutils.BeanUtilsEx;
import com.litt.core.util.ParamUtils;

public class SysInfoServiceImpl implements ISysInfoService {
	
	ISysInfoDAO sysInfoDAO;
		
    /**
     * 从缓存中获取对象
     */
    public SysInfoVO getSysInfoVO()
    {
    	SysInfoVO sysInfoVO = (SysInfoVO)OSCacheManager.loadCacheObject("SYSINFO");
    	if(sysInfoVO==null)
    	{	
    		TbbsSysInfo tbbsSysInfo = sysInfoDAO.load();	    		
   			sysInfoVO = cacheVO(tbbsSysInfo);
    	}
    	return sysInfoVO;
    }
    
	public TbbsSysInfo load()
	{
		return sysInfoDAO.load();
	}
	
	public void update(TbbsSysInfo tbbsSysInfo)
	{
		sysInfoDAO.update(tbbsSysInfo);
		cacheVO(tbbsSysInfo);
	}
    
	public void updateRegAgree(String regAgree)
	{		
		sysInfoDAO.updateRegAgree(regAgree);
	}
	
	public void updateLastReId(int lastReId)
	{
		sysInfoDAO.updateLastReId(lastReId);
	}
	
	public TbbsSysInfo AutoBinding(HttpServletRequest request)
	{
		TbbsSysInfo tbbsSysInfo = new TbbsSysInfo();		
		ParamUtils.DynaBinder(tbbsSysInfo,request);	//动态绑定request值到对象中	
		return tbbsSysInfo;
	}
	
	/**
	 * 缓存数据库对象到VO中
	 * @param tbbsSysInfo
	 */
	public SysInfoVO cacheVO(TbbsSysInfo tbbsSysInfo)
	{
		SysInfoVO vo = new SysInfoVO();
		BeanUtilsEx.copyProperties(vo,tbbsSysInfo);		//将数据库对象中属性的值设到VO对象中
		OSCacheManager.storeCacheObject("SYSINFO",vo);	//缓存对象
		return vo;
	}

	public void setSysInfoDAO(ISysInfoDAO sysInfoDAO) {
		this.sysInfoDAO = sysInfoDAO;
	}
	
	
}
